package com.wxj.book.service.impl;

import com.wxj.book.dao.BorrowMapper;
import com.wxj.book.pojo.Borrow;
import com.wxj.book.pojo.User;
import com.wxj.book.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BorrowServiceImpl  implements BorrowService {
    @Autowired
    private BorrowMapper borrowMapper;

    /**
     * 查询用户是否借阅过该图书
     * @param bookId
     * @return
     */
    @Override
    public Borrow getByBookId(Integer bookId,Integer stuNum) {
        return borrowMapper.getByBookId(bookId, stuNum);
    }

    @Override
    public int insert(User user, Integer bookId) {
        Borrow borrow = new Borrow();
        borrow.setBookId(bookId);
        borrow.setStatus(1);
        borrow.setStuNum(user.getStuNum());
        return borrowMapper.insertSelective(borrow);
    }

    /**
     * 查阅图书上限
     * @param stuNum
     * @return
     */
    @Override
    public int getCountByStuNum(Integer stuNum) {
        return borrowMapper.getCount(stuNum);
    }

    /**
     * 归还图书
     * @param bookId
     * @param stuNum
     * @return
     */
    @Override
    public int backBook(Integer bookId, Integer stuNum) {
        return borrowMapper.backBook(bookId, stuNum);
    }
}
